package com.shenmazong.servereduschool.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduschool.entity.TbCollage;
import com.shenmazong.servereduschool.mapper.TbCollageMapper;
import com.shenmazong.servereduschool.service.ITbCollageService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

/**
 * <p>
 * 学院表——suliven 服务实现类
 * </p>
 *
 * @author 关好帅
 * @since 2021-09-21
 */
@Service
public class TbCollageServiceImpl extends ServiceImpl<TbCollageMapper, TbCollage> implements ITbCollageService {

    @Autowired
    private TbCollageMapper collageMapper;

    @Override
    public ResultResponse registerCollage(TbCollage collage) {
        try {
            collageMapper.insert(collage);
        } catch (Exception e) {
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse queryCollage(ListParamVo paramVo) {
        Page<TbCollage> page =new Page<TbCollage>(paramVo.getCurrent()-1,paramVo.getSize());
        page=collageMapper.selectPage(page, null);
        return ResultResponse.SUCCESS(page);
    }

    @Override
    public ResultResponse updateCollage(TbCollage collage) {
        try {
            collageMapper.updateById(collage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteCollage(BatchChooseIdVo idVo) {
        if(idVo.getIds().size()<=0){
            return ResultResponse.FAILED("请至少选择一个删除");
        }
        try {
            collageMapper.deleteBatchIds(idVo.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}
